home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / MORSETUP.ZIP / APPCHILD.C < prev    next >
C/C++ Source or Header  |  1993-05-07  |  14KB  |  439 lines

  1. #define STRICT
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <shellapi.h>
  5. #include <stdio.h>
  6. #include "morsetup.h"
  7.  
  8. #define MAKECHILD(a,b,c,d,e,f,g,h) CreateWindow(a,b,WS_CHILD | WS_VISIBLE | c,d,e,f,g,hWnd,h,hInst,(LPSTR) NULL)
  9. #define MAKEBUTTON(a,b,c,d,e,f)    MAKECHILD("button",a,BS_PUSHBUTTON,b,c,d,e,f)
  10. #define MAKECHECKBOX(a,b,c,d,e,f)  MAKECHILD("button",a,BS_AUTOCHECKBOX,b,c,d,e,f)
  11. #define MAKERADIO(a,b,c,d,e,f)       MAKECHILD("button",a,BS_RADIOBUTTON,b,c,d,e,f)
  12. #define MAKETEXT(a,b,c,d,e,f)       MAKECHILD("static",a,SS_LEFT,b,c,d,e,f)
  13. #define MAKESTATIC(a,b,c,d)       MAKECHILD("static",NULL,SS_BLACKRECT,a,b,c,d,(HMENU)-1)
  14. #define MAKEBORDER(a,b,c,d)       MAKECHILD("static",NULL,SS_WHITERECT,a,b,c,d,(HMENU) -1)
  15. #define MAKEICON(a,b,c,d,e)       MAKECHILD("button",NULL,BS_OWNERDRAW,a,b,c,d,e)
  16. #define MAKEEDIT(a,b,c,d,e,f)       CreateWindow("edit", "  ", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL | a,b,c,d,e,hWnd,f,hInst,(LPSTR) NULL)
  17.  
  18. /*--------------------------------------------------------------------------*/
  19. VOID UpdateEditWindows(int iCurrent)
  20.     {
  21.     char IcoString[32];
  22.  
  23.     sprintf(IcoString,"Program %d",iCurrent+1);
  24.     Static_SetText(hwndText[0], IcoString);
  25.     Edit_SetText(hwndEdit[0], AppButton[iCurrent].ProgName);
  26.  
  27.     sprintf(IcoString,"Parameters %d",iCurrent+1);
  28.     Static_SetText(hwndText[1], IcoString);
  29.     Edit_SetText(hwndEdit[1], AppButton[iCurrent].Params);
  30.  
  31.     sprintf(IcoString,"Working Directory %d",iCurrent+1);
  32.     Static_SetText(hwndText[2], IcoString);
  33.     Edit_SetText(hwndEdit[2], AppButton[iCurrent].StartDir);
  34.  
  35.     sprintf(IcoString,"Icon %d",iCurrent+1);
  36.     Static_SetText(hwndText[3], IcoString);
  37.     Edit_SetText(hwndEdit[3], AppButton[iCurrent].IcoName);
  38.     }
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. VOID UpdateRadioButtons(int iCurrentRB)
  42.     {
  43.     int i;
  44.  
  45.     bSave = TRUE;
  46.     bSaveButton[iCurrent] = TRUE;
  47.     AppButton[iCurrent].ShowMode = iCurrentRB;
  48.     for(i=0;i<4;i++)
  49.     {
  50.     if(i != iCurrentRB)
  51.         Button_SetCheck(hwndRadioButton[i], 0);
  52.     else
  53.         Button_SetCheck(hwndRadioButton[i], 1);
  54.     }
  55.     }
  56.  
  57. /*--------------------------------------------------------------------------*/
  58. VOID UpdateCheckBoxes(int iCurrent)
  59.     {
  60.     Button_SetCheck(hwndButtonLook, AppButton[iCurrent].ButtonLook);
  61.     Button_SetCheck(hwndCloseProg, AppButton[iCurrent].Close);
  62.     Button_SetCheck(hwndNoSound, AppButton[iCurrent].NoSound);
  63.     }
  64.  
  65.  
  66. /*-------------------------------------------------------------------------*/
  67. VOID UpdateScrollIcons(int iCurrentIcon)
  68.     {
  69.     int i;
  70.  
  71.     iPrevBlackIcon = iBlackIcon;
  72.     iBlackIcon = iCurrentIcon;
  73.     iCurrent -= (iPrevBlackIcon-iCurrentIcon);
  74.     bCurrentIcon[iPrevBlackIcon] = FALSE;
  75.     bCurrentIcon[iBlackIcon] = TRUE;
  76.     UpdateEditWindows(iCurrent);
  77.     UpdateRadioButtons(AppButton[iCurrent].ShowMode);
  78.     UpdateNextButtons(iCurrent);
  79.     UpdateCheckBoxes(iCurrent);
  80.     ScrollBar_SetPos(hwndScroll, iCurrent, TRUE);
  81.     for(i=0;i<NUMICONS;i++)
  82.     {
  83.     InvalidateRect(hwndIcon[i], NULL, TRUE);
  84.     UpdateWindow(hwndIcon[i]);
  85.     }
  86.     }
  87.  
  88. /*--------------------------------------------------------------------------*/
  89. VOID UpdateNextButtons(int iCur)
  90. {
  91.     if(AppButton[iCur].IconNumber <= 0)
  92.     Button_Enable(hwndNext[0], FALSE);
  93.     else
  94.     Button_Enable(hwndNext[0], TRUE);
  95.     if(AppButton[iCur].IconNumber >= MaxIconNumber[iCur]-1)
  96.     Button_Enable(hwndNext[1], FALSE);
  97.     else
  98.     Button_Enable(hwndNext[1], TRUE);
  99. }
  100.  
  101. /*--------------------------------------------------------------------------
  102. VOID CreateAllChildWindows(HWND hWnd, HINSTANCE hInst)
  103.     {
  104.     int i;
  105.     POINT EditWindowPoint[4];
  106.     char *Button[10] ={"Save","Exit","Browse","System","Sound","Sections",
  107.               "Insert","Delete","Move Up","Move Down"};
  108.     char *Next[2] = {"<< "," >>"};
  109.     char *RadioButton[4] = {"Normal","Maximized","Minimized","Maximum size"};
  110.  
  111.     EditWindowPoint[0].x = 110;
  112.     EditWindowPoint[0].y = 32;
  113.     EditWindowPoint[1].x = 110;
  114.     EditWindowPoint[1].y = 90;
  115.     EditWindowPoint[2].x = 110;
  116.     EditWindowPoint[2].y = 148;
  117.     EditWindowPoint[3].x = 110;
  118.     EditWindowPoint[3].y = 206;
  119.  
  120.     // create windows for the icon buttons
  121.     for(i=0;i<NUMICONS;i++)
  122.     {
  123.     hwndIcon[i] = CreateWindow("button",
  124.                   NULL,
  125.                               WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
  126.                   10, 10+68*i,
  127.                   70, 68,
  128.                   hWnd,
  129.                   IDC_ICONS+i,
  130.                               hInst,
  131.                   (LPSTR)NULL);
  132.     }
  133.  
  134.     // create windows for the push buttons
  135.     for(i=0;i<6;i++)
  136.     hwndButton[i] = CreateWindow("button",
  137.                   Button[i],
  138.                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  139.                   409, 10+i*26, 90, 24,
  140.                   hWnd,
  141.                   IDC_BUTTONS+i,
  142.                               hInst,
  143.                   (LPSTR)NULL);
  144.     for(i=6;i<NUMBUTTONS;i++)
  145.     hwndButton[i] = CreateWindow("button",
  146.                   Button[i],
  147.                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  148.                   409, 24+i*26, 90, 24,
  149.                   hWnd,
  150.                   IDC_BUTTONS+i,
  151.                               hInst,
  152.                   (LPSTR)NULL);
  153.     // create windows for the next push buttons beneath "icon"editwindow
  154.     for(i=0;i<2;i++)
  155.     hwndNext[i] = CreateWindow("button",
  156.                   Next[i],
  157.                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  158.                   EditWindowPoint[3].x+i*40,
  159.                   EditWindowPoint[3].y+27,
  160.                   40, 18,
  161.                   hWnd,
  162.                   IDC_NEXT+i,
  163.                               hInst,
  164.                   (LPSTR)NULL);
  165.  
  166.     // create windows for buttonlook option checkbox
  167.     hwndButtonLook = CreateWindow("button",
  168.                   "Buttonlook",
  169.                   WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
  170.                   260, 264, 120, 20,
  171.                   hWnd,
  172.                   IDC_BUTTONLOOK,
  173.                   hInst,
  174.                   (LPSTR)NULL);
  175.  
  176.     // create windows for the showmode radiobuttons
  177.     for(i=0;i<4;i++)
  178.     hwndRadioButton[i] = CreateWindow("button",
  179.                   RadioButton[i],
  180.                   WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON,
  181.                   115, 264+i*20, 120, 18,
  182.                   hWnd,
  183.                   IDC_RADIOS+i,
  184.                               hInst,
  185.                   (LPSTR)NULL);
  186.  
  187.     // create windows for close option checkbox
  188.     hwndCloseProg = CreateWindow("button",
  189.                   "Close Program",
  190.                   WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
  191.                   260, 284, 120, 20,
  192.                   hWnd,
  193.                   IDC_CLOSEPROG,
  194.                               hInst,
  195.                   (LPSTR)NULL);
  196.  
  197.     // create edit textwindows
  198.     for(i=0;i<NUMEDITS;i++)
  199.     {
  200.     if(i != 1)
  201.         hwndEdit[i] = CreateWindow("edit",
  202.                   "  ",
  203.                   WS_CHILD | WS_VISIBLE | WS_BORDER |
  204.                   ES_LEFT | ES_LOWERCASE | ES_AUTOHSCROLL,
  205.                   EditWindowPoint[i].x, EditWindowPoint[i].y,
  206.                   280, 28,
  207.                   hWnd,
  208.                   IDC_EDITS+i,
  209.                               hInst,
  210.                   (LPSTR)NULL);
  211.     if(i == 1)
  212.         hwndEdit[i] = CreateWindow("edit",
  213.                   " ",
  214.                   WS_CHILD | WS_VISIBLE | WS_BORDER |
  215.                   ES_LEFT | ES_AUTOHSCROLL,
  216.                   EditWindowPoint[i].x, EditWindowPoint[i].y,
  217.                   280, 28,
  218.                   hWnd,
  219.                   IDC_EDITS+i,
  220.                               hInst,
  221.                   (LPSTR)NULL);
  222.  
  223.     Edit_LimitText(hwndEdit[i], MAXFILECHARS-1);
  224.     lpfnOldEdit[i] = (FARPROC) GetWindowLong(hwndEdit[i], GWL_WNDPROC);
  225.     SetWindowLong(hwndEdit[i], GWL_WNDPROC,
  226.           (LONG) MakeProcInstance( (FARPROC) EditProc,
  227.           (HINSTANCE) GetWindowWord(hWnd, GWW_HINSTANCE)));
  228.  
  229.     // create static text windows
  230.     hwndText[i] = CreateWindow("static",
  231.                   "    ",
  232.                   WS_CHILD | WS_VISIBLE | SS_LEFT,
  233.                   EditWindowPoint[i].x, EditWindowPoint[i].y-21,
  234.                   140, 20,
  235.                   hWnd,
  236.                   IDC_TEXTS+i,
  237.                               hInst,
  238.                   (LPSTR)NULL);
  239.     }
  240.  
  241.     // create scrollbar next to the iconbuttons
  242.     hwndScroll = CreateWindow("scrollbar", NULL,
  243.                   WS_CHILD | WS_VISIBLE | SBS_VERT,
  244.                   80, 9, 20, 342,
  245.                   hWnd,
  246.                   IDC_SCROLL,
  247.                   hInst,
  248.                   (LPSTR)NULL);
  249.     }  */
  250. /*--------------------------------------------------------------------------*/
  251. VOID CreateAllChildWindows(HWND hWnd, HINSTANCE hInst)
  252.     {
  253.     int i;
  254.     char *Button[NUMBUTTONS] ={"Save","Exit","Browse","System","Sound","Sections",
  255.               "Help","Insert","Delete","Move Up","Move Down"};
  256.     char *Next[2] = {"<< "," >>"};
  257.     char *RadioButton[4] = {"Normal","Maximized","Minimized","Maximum size"};
  258.  
  259.     // create static frame around Icons+scroll and editwindows
  260.     Ctl3dSubclassCtl(MAKEBORDER(0, 0, 512, 359));
  261.     Ctl3dSubclassCtl(MAKESTATIC(9, 9, 388, 342));
  262.  
  263.     // create static frame around buttons
  264.     Ctl3dSubclassCtl(MAKESTATIC(406, 9, 98, 342));
  265.  
  266.     // create static frame around checkboxes and radiobuttons
  267.     Ctl3dSubclassCtl(MAKESTATIC(110, 260, 280, 86));
  268.  
  269.     // create windows for the icon buttons
  270.     for(i=0;i<NUMICONS;i++)
  271.     hwndIcon[i] = MAKEICON(10, 10+68*i, 70, 68, IDC_ICONS+i);
  272.  
  273.     // create windows for the push buttons
  274.     for(i=0;i<7;i++)
  275.     hwndButton[i] = MAKEBUTTON(Button[i], 410, 14+i*26, 90, 24,
  276.                    IDC_BUTTONS+i);
  277.  
  278.     for(i=7;i<NUMBUTTONS;i++)
  279.     hwndButton[i] = MAKEBUTTON(Button[i], 410, 28+i*26, 90, 24,
  280.                   IDC_BUTTONS+i);
  281.  
  282.     // create windows for the next push buttons beneath "icon"editwindow
  283.     for(i=0;i<2;i++)
  284.     hwndNext[i] = MAKEBUTTON(Next[i], 110+i*40, 60+(NUMEDITS-1)*58,
  285.                  40, 18, IDC_NEXT+i);
  286.  
  287.     // create windows for buttonlook option checkbox
  288.     hwndButtonLook = MAKECHECKBOX("Buttonlook", 260, 264, 120, 20,
  289.                   IDC_BUTTONLOOK);
  290.     Ctl3dSubclassCtl(hwndButtonLook);
  291.  
  292.     // create windows for no sound option checkbox
  293.     hwndNoSound = MAKECHECKBOX("No Sound", 260, 304, 120, 20,
  294.                   IDC_NOSOUND);
  295.     Ctl3dSubclassCtl(hwndNoSound);
  296.  
  297.     // create windows for close option checkbox
  298.     hwndCloseProg = MAKECHECKBOX("Close Program", 260, 284, 120, 20,
  299.                   IDC_CLOSEPROG);
  300.     Ctl3dSubclassCtl(hwndCloseProg);
  301.  
  302.     // create windows for the showmode radiobuttons
  303.     for(i=0;i<4;i++)
  304.     {
  305.     hwndRadioButton[i] = MAKERADIO(RadioButton[i], 115, 264+i*20, 130, 18,
  306.                   IDC_RADIOS+i);
  307.     Ctl3dSubclassCtl(hwndRadioButton[i]);
  308.     }
  309.  
  310.     // create edit textwindows
  311.     for(i=0;i<NUMEDITS;i++)
  312.     {
  313.     if(i != 1)
  314.         hwndEdit[i] = MAKEEDIT(ES_LOWERCASE, 110, 32+i*58, 280, 28,
  315.                    IDC_EDITS+i);
  316.     if(i == 1)
  317.         hwndEdit[i] = MAKEEDIT(0, 110, 32+i*58, 280, 28, IDC_EDITS+i);
  318.  
  319.     Ctl3dSubclassCtl(hwndEdit[i]);
  320.     Edit_LimitText(hwndEdit[i], MAXFILECHARS-1);
  321.     lpfnOldEdit[i] = (FARPROC) GetWindowLong(hwndEdit[i], GWL_WNDPROC);
  322.     SetWindowLong(hwndEdit[i], GWL_WNDPROC,
  323.           (LONG) MakeProcInstance( (FARPROC) EditProc,
  324.           (HINSTANCE) GetWindowWord(hWnd, GWW_HINSTANCE)));
  325.  
  326.     // create static text windows
  327.     hwndText[i] = MAKETEXT("   ", 110, 11+i*58, 140, 20, IDC_TEXTS+i);
  328.     }
  329.  
  330.     // create scrollbar next to the iconbuttons
  331.     hwndScroll = MAKECHILD("scrollbar", NULL, SBS_VERT, 80, 10, 20, 340,
  332.                IDC_SCROLL);
  333.     }
  334.  
  335. /*--------------------------------------------------------------------------*/
  336. VOID Insert(VOID)
  337.     {
  338.     int i;
  339.     for(i=MAXAPPS-1;i>iCurrent;i--)
  340.     {
  341.     AppButton[i] = AppButton[i-1];
  342.     hIcon[i] = hIcon[i-1];
  343.     if(hIcon[i] != NULL)
  344.         bSaveButton[i] = TRUE;
  345.     }
  346.     AppButton[iCurrent] = AppButtonDefault;
  347.     hIcon[iCurrent] = NULL;
  348.     UpdateScrollIcons(iBlackIcon);
  349.     bSave = TRUE;
  350.     }
  351.  
  352. /*-------------------------------------------------------------------------*/
  353. VOID Delete(VOID)
  354.     {
  355.     int i;
  356.  
  357.     for(i=iCurrent;i<MAXAPPS-1;i++)
  358.     {
  359.     AppButton[i] = AppButton[i+1];
  360.     if(hIcon[i] != NULL)
  361.         bSaveButton[i] = TRUE;
  362.     hIcon[i] = hIcon[i+1];
  363.     }
  364.     AppButton[MAXAPPS-1] = AppButtonDefault;
  365.     hIcon[MAXAPPS-1] = NULL;
  366.     UpdateScrollIcons(iBlackIcon);
  367.     bSave = TRUE;
  368.     }
  369.  
  370. /*--------------------------------------------------------------------------*/
  371. VOID MoveUp(VOID)
  372.     {
  373.     if(iCurrent > 0)
  374.     {
  375.     AppButtonTemp = AppButton[iCurrent-1];
  376.     AppButton[iCurrent-1] = AppButton[iCurrent];
  377.     AppButton[iCurrent] = AppButtonTemp;
  378.     hIconTemp = hIcon[iCurrent-1];
  379.     hIcon[iCurrent-1] = hIcon[iCurrent];
  380.     hIcon[iCurrent] = hIconTemp;
  381.     bSaveButton[iCurrent-1] = TRUE;
  382.     bSaveButton[iCurrent] = TRUE;
  383.     bSave = TRUE;
  384.     iCurrent--;
  385.     iBlackIcon--;
  386.     iBlackIcon = max(0, min(iBlackIcon, NUMICONS-1));
  387.     bCurrentIcon[iPrevBlackIcon] = FALSE;
  388.     bCurrentIcon[iBlackIcon+1] = FALSE;
  389.     UpdateScrollIcons(iBlackIcon);
  390.     }
  391.     }
  392.  
  393. /*--------------------------------------------------------------------------*/
  394. VOID MoveDown(VOID)
  395.     {
  396.     if(iCurrent < MAXAPPS-1)
  397.     {
  398.     AppButtonTemp = AppButton[iCurrent];
  399.     AppButton[iCurrent] = AppButton[iCurrent+1];
  400.     AppButton[iCurrent+1] = AppButtonTemp;
  401.     hIconTemp = hIcon[iCurrent];
  402.     hIcon[iCurrent] = hIcon[iCurrent+1];
  403.     hIcon[iCurrent+1] = hIconTemp;
  404.     bSaveButton[iCurrent+1] = TRUE;
  405.     bSaveButton[iCurrent] = TRUE;
  406.     bSave = TRUE;
  407.     iCurrent++;
  408.     iBlackIcon++;
  409.     iBlackIcon = max(0, min(iBlackIcon, NUMICONS-1));
  410.     bCurrentIcon[iPrevBlackIcon] = FALSE;
  411.     bCurrentIcon[iBlackIcon-1] = FALSE;
  412.     UpdateScrollIcons(iBlackIcon);
  413.     }
  414.     }
  415.  
  416. /*--------------------------------------------------------------------------*/
  417. VOID Next(int i)
  418.     {
  419.     bSave = TRUE;
  420.     bSaveButton[iCurrent] = TRUE;
  421.     if(i == DOWN)
  422.     {
  423.     AppButton[iCurrent].IconNumber--;
  424.     AppButton[iCurrent].IconNumber = max(0, AppButton[iCurrent].IconNumber);
  425.     }
  426.     if(i == UP)
  427.     {
  428.     AppButton[iCurrent].IconNumber++;
  429.     AppButton[iCurrent].IconNumber = min(MaxIconNumber[iCurrent]-1, AppButton[iCurrent].IconNumber);
  430.     }
  431.     DestroyIcon(hIcon[iCurrent]);
  432.     hIcon[iCurrent] = ExtractIcon(hInst, AppButton[iCurrent].IcoName, AppButton[iCurrent].IconNumber);
  433.     if(hIcon[iCurrent] == (HICON) 1)
  434.     hIcon[iCurrent] = NULL;
  435.     InvalidateRect(hwndIcon[iBlackIcon], NULL, FALSE);
  436.     UpdateWindow(hwndIcon[iBlackIcon]);
  437.     UpdateNextButtons(iCurrent);
  438.     }
  439.